#include<bits/stdc++.h>
using namespace std;
class Solution {
public:
    long long maximumProduct(vector<int>& nums, int m) {
        int n = nums.size();
        vector<int> maxs(n);
        vector<int> mins(n);
        maxs[0] = nums[0];
        mins[0] = nums[0];
        long long k = (long long)nums[0] * (long long)nums[0];
        for (int i = 1; i < nums.size(); i++) {
            maxs[i] = max(nums[i], maxs[i - 1]);
            mins[i] = min(nums[i], mins[i - 1]);
            long long s = (long long)nums[i] * (long long)nums[i];
            k = max(k, s);
        }
        if (m == 1)
            return k;
        long long result = (long long)nums[m - 1] * (long long)nums[0];
        for (int j = m; j < nums.size(); j++) {
            long long a1 = (long long)nums[j] * (long long)mins[j - m + 1];
            long long a2 = (long long)nums[j] * (long long)maxs[j - m + 1];
            if (nums[j] < 0)
                result = max(result, a1);
            else
                result = max(result, a2);
        }
        return result;
    }
};//
// Created by LENOVO on 2025/8/6.
//
